package com.eling.elcms.travel.event;

import com.eling.elcms.basedoc.model.BusinessMessage;
import com.eling.elcms.basedoc.service.IBusinessMessageManager;
import com.eling.elcms.core.AppContext;
import com.eling.elcms.privilege.service.IRbacService;
import com.eling.elcms.sos.service.IToDoItemBiz;
import com.eling.elcms.sos.view.ToDoItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TravelServiceToDoListener implements IToDoItemBiz {
	
	@Autowired
	private IRbacService rbacService;
	
	@Autowired
	private IBusinessMessageManager businessMessageManager;

	@Override
	public List<ToDoItem> query() {
		List<ToDoItem> toDoList = new ArrayList<ToDoItem>();
		List<Long> pkRoleList = rbacService.getUserAssignment(AppContext.curUser().getPkUser(), "role");
		List<BusinessMessage> businessList = businessMessageManager.queryBusiness(AppContext.curUser().getPkUser(), pkRoleList);
		if(!businessList.isEmpty()){
			for(BusinessMessage bm : businessList){
				ToDoItem toDoItem = new ToDoItem();
				toDoItem.setPkBusinessMessage(bm.getPkBusinessMessage());
				toDoItem.setDate(bm.getCreateDate());
				toDoItem.setImportant(bm.getImportant());
				toDoItem.setPageLink(bm.getPageLink());
				toDoItem.setPageParameter(bm.getPageParameter());
				toDoItem.setTitle(bm.getTitle());
				toDoList.add(toDoItem);
			}
		}
		return toDoList;
	}

}
